import http from "@/axios/index.js";
import { handleError, handleSuccess } from "@/utils/responseHandler.js";

export const UserApi = {
    getUserList: (params) => {
        return http.get('/user', { params });
    },

    registerPublic: (data) => http.post('/user/register/public', data)
        .then(res => handleSuccess(res, '公众注册'))
        .catch(error => handleError(error, '公众注册', '注册失败，请检查输入信息格式')),

    registerLawyer: (data) => http.post('/user/register/lawyer', data)
        .then(res => handleSuccess(res, '律师注册'))
        .catch(error => handleError(error, '律师注册', '执照上传失败，请检查文件格式')),

    login: (data) => http.post('/user/login', data)
        .then(res => handleSuccess(res, '登录'))
        .catch(error => handleError(error, '登录', '登录失败，请检查输入信息格式')),

    // 新增用户
    createUser: (data) => http.post('/user/create', data)
        .then(res => handleSuccess(res, '新增用户'))
        .catch(error => handleError(error, '新增用户', '新增用户失败，请检查输入信息格式')),

    // 更新用户
    updateUser: (data) => http.post('/user/update', data)
        .then(res => handleSuccess(res, '更新用户'))
        .catch(error => handleError(error, '更新用户', '更新用户失败，请检查输入信息格式')),

    //删除用户
    deleteUser: (id) => http.delete(`/user/delete/${id}`)
        .then(res => handleSuccess(res, '删除用户'))
        .catch(error => handleError(error, '删除用户', '删除用户失败，请检查输入信息格式')),

    // 获取用户详情
    getUserDetail: (id) => http.get(`/user/detail/${id}`)
        .then(res => handleSuccess(res, '获取用户详情'))
        .catch(error => handleError(error, '获取用户详情', '获取用户详情失败，请检查输入信息格式')),

    // 分页查询用户列表,包含查询条件,条件在问号后
    getUserListByPage: (params) => http.get('/user/page', {params:params})
        .then(res => handleSuccess(res, '分页查询用户列表'))
        .catch(error => handleError(error, '分页查询用户列表', '分页查询用户列表失败，请检查输入信息格式')),

    //重置密码
    resetPassword: (data) => http.post('/user/resetPassword', data)
        .then(res => handleSuccess(res, '重置密码'))
        .catch(error => handleError(error, '重置密码', '重置密码失败，请检查输入信息格式')),

    //切换用户状态
    updateStatus: (data) => http.post('/user/status', data)
        .then(res => handleSuccess(res, '切换用户状态'))
        .catch(error => handleError(error, '切换用户状态', '切换用户状态失败，请检查输入信息格式')),

}